package com.lpc.android.abc.base.di.module;

import android.app.Application;
import android.content.Context;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.lpc.android.abc.base.R;
import com.lpc.android.abc.base.di.scope.AppScope;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;

/**
 * Created by lpc on 2017/1/11 0011.
 */

@Module
public class AppModule {

    private Application mApplication;

    public AppModule(Application application) {

        mApplication = application;
    }

    @Provides
    public Application provideApplication() {
        return mApplication;
    }

    @Provides
    public Context provideContext() {
        return mApplication;
    }

    @AppScope
    @Provides
    public Gson provideGson(){
        GsonBuilder builder = new GsonBuilder();
        return builder.create();
    }

    @Provides
    public RequestOptions provideRequestOptions(){

        RequestOptions options = new RequestOptions();
        options.diskCacheStrategy(DiskCacheStrategy.RESOURCE);
        return options;
    }

    @AppScope
    @Provides
    public RequestManager provideRequestManager(Context context, RequestOptions options){

        RequestManager glide = Glide.with(context).setDefaultRequestOptions(options);
        return glide;
    }
}
